<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/style.css" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">

	function change(obj){
		// 获取role id 值
		var rid = obj.title;
		
		var r2 = $("input[title = " + rid + "][lang = " + obj.value + "]");
		
		r2.each(function(i){
			if(obj.checked == true){
				$(this).prop("checked", true);
			}else{
				$(this).prop("checked", false);
			}
		});
		
		// 获取此行所有复选框
 	 $.get("${pageContext.request.contextPath}/RoleServlet?m=update",{"menuID":obj.value,"stat":obj.checked,"roleID":obj.title},function(d){
 		
 		/* var r1;
 		$.each(d, function(index, obj){
	 			//alert(obj.menuname);
	 			// 获取修改角色行的所有复选框
	 			r1 =  $("input[title = " + rid + "][value = " + obj.id + "]");
	 			r1.prop("checked", true);

	 		}); */
 		
		},"json");  
	}
</script>
</head>
<body >
	<div class="all" >
		<div class="mid">
			<div class="right">
				<table border="0" >
					<tr bgcolor="#3992d0">
						<td>角色名</td>
						
						
						<c:forEach items="${menusList}" var="m">
							<td>${m.functionName}</td>
						</c:forEach>
						<td></td>
					</tr>
					<c:forEach items="${roles }" var="r">
						<tr lang="${r.roleID}" >
							<td>${r.roleName }</td>							
							<%-- <td>${r.desc } </td>	 --%>
							<c:forEach items="${menusList}" var="m">
								<td width="0.8%" >
									<input type="checkbox" name ="${m.functionName }" title="${r.roleID }" lang="${m.foreID }" value="${m.menuID }"  onclick="change(this)"
										 <c:forEach items="${r.menuIDs }" var="menu">	
											<c:if test="${menu == m.menuID}">
												checked="checked"
											</c:if>
										</c:forEach> 
										/>						
								</td>
							</c:forEach>
							<td><a href="javascript:void()" onclick="del('${r.roleID}')">删除</a></td>
						</tr>
					</c:forEach>
				</table>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function del(roleID){
		if(confirm("删除是不可恢复的，你确认要删除此角色吗?")){
			//location.href = "${pageContext.request.contextPath}/admin/roleManage?m=del&roleid=" + id;
			$.get("${pageContext.request.contextPath}/RoleServlet?m=del",{"roleID":roleID},function(roleID){
				//alert(roleID);
				$("tr[lang=" +roleID + "]").remove();
			});
		}
	}
</script>
</html>

